<template>
  <div class="login-page">
    <div class="layer bg" id="login"></div>
    <div class="layer flex-center">
      <!-- logo部分 -->
      <div class="logo-group">
        <span class="title">展超医疗问卷管理系统</span>
        <div class="img"><img src="./image/logo.png" alt="logo"></div>
      </div>
      <!-- 表单部分 -->
      <div class="form-group">
        <el-card >
          <el-form ref="loginForm" label-position="top" :rules="rules" :model="formLogin">
            <el-form-item  prop="username" label="请输入病历号登录">
              <el-input type="text" v-model="formLogin.username" size="large" placeholder="检索条件">
              </el-input>
            </el-form-item>
            <el-button @click="search" type="primary" class="button-login">进入</el-button>
          </el-form>
        </el-card>
      </div>
    </div>
  </div>
</template>

<script>
/* eslint-disable */
require('particles.js')
import config from './config/default'
import util from '@/libs/util.js'
import PatientApi from '@/api/patientApi.js'
let patientApi = new PatientApi()


export default {
  data () {
    return {
      // 表单
      formLogin: {
        username: 'admin'
      },
      // 校验
      rules: {
        username: [
          { required: true, message: '请输入条件进行检索', trigger: 'blur' }
        ]
      }
    }
  },
  mounted () {
    // 初始化例子插件
    particlesJS('login', config)
  },
  methods: {
    /**
     * @description 提交表单
     */
    search () {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
            let userInfo = {}
            let url = '/auth/searchPatient?medicalNumber=' + this.formLogin.username
            this.$axios.get(url).then(r => {
                let {code, data, msg} = r
                if (code === 0) {
                    userInfo.patientId = data.id
                    userInfo.patientName = data.name
                    userInfo.medicalNumber = data.medicalNumber
                    util.cookies.set('userInfo', userInfo)
                    util.cookies.set('token', 'uuid')
                    this.$store.state.myStore.patient = data
                    // 跳转路由
                    this.$router.push({
                        name: 'home'
                    })
                } else {
                    this.$message({
                        message: msg,
                        type: 'warning'
                    });
                }
            })
        }
      })
    }
  }
}
</script>

<style lang="scss">
@import './style.scss';
</style>
